import { JSEncrypt } from "jsencrypt";
//秘钥必须为：8/16/32位
import CryptoJS from "crypto-js";
const encryptStr = (12121.2234).toString(32);
export function encrypt(message: string) {
  return CryptoJS.AES.encrypt(
    message,
    CryptoJS.enc.Utf8.parse(encryptStr.slice(2, 10)),
    {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7,
    }
  ).toString();
}
export function decrypt(message: string) {
  return CryptoJS.AES.decrypt(
    message,
    CryptoJS.enc.Utf8.parse(encryptStr.slice(2, 10)),
    {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7,
    }
  ).toString(CryptoJS.enc.Utf8);
}
export function encryptRSA(message: string, publicKey: string) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey);
  const encryptedStr = encryptor.encrypt(message);
  return encryptedStr;
}
export function decryptRSA(message: string, privateKey: string) {
  const decryptor = new JSEncrypt();
  decryptor.setPrivateKey(privateKey);
  const decryptedStr = decryptor.decrypt(message);
  return decryptedStr;
}
